package com.mark.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * Created by Mark on 2018/3/26.
 */
@Slf4j
public class PropertiesUtil {
    private static Properties properties;
    public static  final String  FTP_SERVER_HTTP_PREFIX =  "http://img.mark.com/";

    static {//在静态代码块中读取配置问价
        String fileName = "campus.properties";
        properties  = new Properties();
        try {
            properties.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName),"UTF-8"));
        } catch (IOException e) {
            log.error("PropertiesUtil中读取配置文件异常："+e.getMessage());
        }
    }

    public static String getProperty(String key){
        String value = properties.getProperty(key);
        if (StringUtils.isBlank(value)){
            return null;
        }
        return value.trim();
    }

    public static String getProperty(String key,String defaultValue){
        String value = properties.getProperty(key.trim());
        if(StringUtils.isBlank(value)){
            value = defaultValue;
        }
        return value.trim();
    }


}
